﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MShop.Core;
using MShop.Core.DataAccess;
using MShop.Core.Domain;

namespace MShop.Web.Areas.Admin.Controllers
{
    public class EmailTemplateController : SecureController
    {
        private IEmailTemplateDao _CommonDao;

        public EmailTemplateController(IEmailTemplateDao commonDao)
        {
            _CommonDao = commonDao;
        }

        public ActionResult Index()
        {
            var q = _CommonDao.GetAll();
            return View(q);
        }


        public ActionResult Edit(int id)
        {
           
            var q = _CommonDao.GetById(id);
            ViewData["EmailEntity"] = _CommonDao.GetEmailEntity(id);
            return View(q);
        }

        [HttpPost]
        [ValidateInput(false)]
        public ActionResult Edit(int id,FormCollection form)
        {
            var q = _CommonDao.GetById(id);
            ViewData["EmailEntity"] = _CommonDao.GetEmailEntity(id);
            UpdateModel<EmailTemplate>(q, new string[] { "Subject", "EmailType", "EmailTips", "TemplateValues", "Priority" });
            _CommonDao.SaveChanges();
            return View(q);
        }
    }
}
